package com.example.pinkcat.adapter;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.pinkcat.R;
import com.example.pinkcat.activity.VideoActivity;
import com.example.pinkcat.activity.VideoPinkcat;
import com.example.pinkcat.activity.ViewAllMyFollow;
import com.example.pinkcat.activity.api.entity.VideoEntity;
import com.example.pinkcat.api.entity.VideowaibuEntity;
import com.example.pinkcat.api.entity.videoMsg;
import com.rishabhharit.roundedimageview.RoundedImageView;

import java.util.ArrayList;
import java.util.List;

public class Remen_FragmentPagerAdapter extends RecyclerView.Adapter<Remen_FragmentPagerAdapter.ViewHodler> {

    private Context context;

    String style ;

    List<VideowaibuEntity> videoMsgArrayList=new ArrayList<>();



    public void setData(List<VideowaibuEntity> videoEntities, String style){
        this.videoMsgArrayList = videoEntities;
        this.style = style;
        notifyDataSetChanged();
    }

    public void addData(List<VideowaibuEntity> videoEntities,String style){
        this.videoMsgArrayList.addAll(videoEntities);
        this.style = style;
        notifyDataSetChanged();
    }

    public Remen_FragmentPagerAdapter(Context context,String style) {
        this.context = context;
        this.style = style;
    }

    static class ViewHodler extends RecyclerView.ViewHolder {
        private RoundedImageView roundedImageView;
        private TextView textView_titile;
        private ImageView imageView_1;
        private TextView textView_1;

        private ImageView imageView_2;
        private TextView textView_2;

        private ImageView imageView_3;
        private TextView textView_3;

        private View list_video;

        public ViewHodler(@NonNull View itemView) {
            super(itemView);
            roundedImageView = (RoundedImageView) itemView.findViewById(R.id.video_face);
            textView_titile = itemView.findViewById(R.id.about_v_title);

            imageView_1 = (ImageView) itemView.findViewById(R.id.list_img_1);
            textView_1 = (TextView) itemView.findViewById(R.id.about_username);

            imageView_2 = (ImageView) itemView.findViewById(R.id.list_img_2);
            textView_2 = (TextView) itemView.findViewById(R.id.about_bfsl);

            imageView_3 = (ImageView) itemView.findViewById(R.id.list_img_3);
            textView_3 = (TextView) itemView.findViewById(R.id.about_plsl);

            list_video = itemView.findViewById(R.id.list_main_body);
        }
    }


    //创建view
    @NonNull
    @Override
    public Remen_FragmentPagerAdapter.ViewHodler onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.list_aboutvideo,parent,false);

        return new Remen_FragmentPagerAdapter.ViewHodler(view);
    }

    //数据绑定
    @Override
    public void onBindViewHolder(@NonNull ViewHodler holder, int position) {


        if (style.equals("day")) {
            Glide.with(context).load(Uri.parse(videoMsgArrayList.get(position).getVideo_cover())).into(holder.roundedImageView); //视频封面
            holder.textView_titile.setText(videoMsgArrayList.get(position).getVideo_name()); //视频标题
            holder.textView_1.setText(videoMsgArrayList.get(position).getUser_name()); //视频发布者
            holder.textView_2.setText(String.valueOf(videoMsgArrayList.get(position).getDayplay())); //视频播放量
            holder.textView_3.setText(String.valueOf(videoMsgArrayList.get(position).getCount())); //评论数量
        }else if (style.equals("week")){
            Glide.with(context).load(Uri.parse(videoMsgArrayList.get(position).getVideo_cover())).into(holder.roundedImageView); //视频封面
            holder.textView_titile.setText(videoMsgArrayList.get(position).getVideo_name()); //视频标题
            holder.textView_1.setText(videoMsgArrayList.get(position).getUser_name()); //视频发布者
            holder.textView_2.setText(String.valueOf(videoMsgArrayList.get(position).getWeekplay())); //视频播放量
            holder.textView_3.setText(String.valueOf(videoMsgArrayList.get(position).getCount())); //评论数量
        }



            holder.list_video.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (videoMsgArrayList.get(position).getVideo_type().equals("综艺")||
                            videoMsgArrayList.get(position).getVideo_type().equals("电视剧")||
                            videoMsgArrayList.get(position).getVideo_type().equals("电影")||
                            videoMsgArrayList.get(position).getVideo_type().equals("动漫"))
                    {
                        Intent intent=new Intent(context, VideoPinkcat.class);
                        intent.putExtra("v_id",videoMsgArrayList.get(position).getVideo_id());
                        intent.putExtra("up_id",videoMsgArrayList.get(position).getUser_id());
                        intent.putExtra("v_link",videoMsgArrayList.get(position).getVideo_link());
                        intent.putExtra("v_labs",videoMsgArrayList.get(position).getVideo_lab());
                        context.startActivity(intent);
                    }
                    else {
                        Intent intent=new Intent(context, VideoActivity.class);
                        intent.putExtra("v_id",videoMsgArrayList.get(position).getVideo_id());
                        intent.putExtra("up_id",videoMsgArrayList.get(position).getUser_id());
                        intent.putExtra("v_link",videoMsgArrayList.get(position).getVideo_link());
                        intent.putExtra("v_labs",videoMsgArrayList.get(position).getVideo_lab());
                        context.startActivity(intent);
                    }
                }
             });
        }



    @Override
    public int getItemCount() {

        return  videoMsgArrayList.size();
    }
}
